package com.cvtc29.www;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class Marrisug extends Activity{

	private Button BU001;

	private RadioGroup radGSex, radGAge;
	private RadioButton RB003, RB004, RB005;
    private TextView TE001,TE002,TE003,TE004,TE005,TE006;
    private String sSex;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        setupViewComponent();
    }
    
    private void setupViewComponent() {
        // 從資源類別R中取得介面元件
        BU001 = (Button)findViewById(R.id.BU001);

        radGSex = (RadioGroup)findViewById(R.id.radGSex);
    	radGAge = (RadioGroup)findViewById(R.id.radGAge);
    	RB003 = (RadioButton)findViewById(R.id.RB003);
    	RB004 = (RadioButton)findViewById(R.id.RB004);
    	RB005 = (RadioButton)findViewById(R.id.RB005);
      	TE001 = (TextView)findViewById(R.id.TE001);
    	TE002 = (TextView)findViewById(R.id.TE002);
    	TE003 = (TextView)findViewById(R.id.TE003);

    	BU001.setOnClickListener(btnDoSugOnClick);
    	radGSex.setOnCheckedChangeListener(radGSexOnCheChanLis);
    }
    
    private RadioGroup.OnCheckedChangeListener radGSexOnCheChanLis = new RadioGroup.OnCheckedChangeListener () {
    	public void onCheckedChanged(RadioGroup group, int checkedId)
    	{
    		if (checkedId == R.id.RB010) {
    			RB003.setText(getString(R.string.RB011));
    			RB004.setText(getString(R.string.RB012));
    			RB005.setText(getString(R.string.RB013));
    			RB005.setChecked(true);
    		}
    		else if (checkedId == R.id.RB020) {
    			RB003.setText(getString(R.string.RB021));
    			RB004.setText(getString(R.string.RB022));
    			RB005.setText(getString(R.string.RB023));
    			RB003.setChecked(true);
    		}
    	}
    };
    
    private Button.OnClickListener btnDoSugOnClick = new Button.OnClickListener() {
		public void onClick(View v) {
			int iCheckedRadBtn = radGSex.getCheckedRadioButtonId();
			
			String strSug = getString(R.string.TE003);
			switch (iCheckedRadBtn)
			{
			case R.id.RB010:
				switch (radGAge.getCheckedRadioButtonId())
				{
				case R.id.RB003:
					strSug += getString(R.string.TE004);
					break;
				case R.id.RB004:
					strSug += getString(R.string.TE005);
					break;
				default:
					strSug += getString(R.string.TE006);
				}
				break;
			case R.id.RB020:
				switch (radGAge.getCheckedRadioButtonId())
				{
				case R.id.RB003:
					strSug += getString(R.string.TE004);
					break;
				case R.id.RB004:
					strSug += getString(R.string.TE005);
					break;
				default:
					strSug += getString(R.string.TE006);
				}
				break;
			}
			
			TE003.setText(strSug);
		}
	};
}	

